<?php

namespace App\Admin\Controllers;

use App\Models\Reward;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Controllers\AdminController;

class RewardsController extends AdminController
{
    protected $title = '积分兑换记录';
    
    protected function grid()
    {
        $grid = new Grid(new Reward());
	
	    $grid->disableExport();
	    
	    $grid->column('user_id', '会员')->display(function () {
	    	return $this->user ? $this->user->namePhone(true) : '';
	    });
	    $grid->column('product_id', '商品名称')->display(function () {
	    	return $this->product ? $this->product->title : '';
	    });

	    $grid->column('is_open', '兑换状态')->display(function ($value) {
		    return $value ? _label('已兑换', 'success') : _label('未兑换', 'default');
	    });
	   
	    $grid->column('created_at', '创建时间')->display(function () {
	    	return $this->created_at->toDatetimeString();
	    });

	   $this->gridActions($grid);
	  
        return $grid;
    }
    
    protected function gridActions(Grid $grid)
	{
		$grid->actions(function (Grid\Displayers\Actions $actions) {
			$actions->disableView();
			$actions->disableDelete();
			//$actions->add(new RefreshBlindBoxRate());
		});
	}

	protected function form()
    {
        $form = new Form(new Reward());

		$form->radio('is_open', '兑换状态')->default(false)->options(config('site.bool'));

        return $form;
    }

}
